package com.yunfangdata.service.impl;

import com.yunfangdata.domain.Gathering;
import com.yunfangdata.mapper.GatheringMapper;
import com.yunfangdata.query.GatheringQueryObject;
import com.yunfangdata.service.IGatheringService;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GatheringServiceImpl implements IGatheringService {

    @Autowired
    private GatheringMapper mapper ;
    @Override
    public void save(Gathering entity) {
        mapper.insert(entity);
    }

    @Override
    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public void update(Gathering entity) {
        mapper.updateByPrimaryKey(entity);
    }

    @Override
    public Gathering get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Gathering> list() {
        return mapper.selectAll();
    }

    @Override
    public PageResult query(GatheringQueryObject qo) {
        int total = mapper.queryForCount(qo);

        if (total == 0){
            return new PageResult();
        }
        List<Gathering> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }

    @Override
    public void changeState(Long id) {
        mapper.changeState(id);
    }

}